/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.i.kotionokyurievna.jewelryweb.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author Kateryna_Reznik
 */
public class PasswordEncryptor {
    
    public String encrypt( String string){
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            byte[] secured = md.digest(string.getBytes("UTF-8"));
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < secured.length; i++) {
                sb.append(Integer.toString((secured[i] & 0xff) + 0x100, 16)
		      .substring(1));
            }
            return sb.toString();
	} catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
	   return null; // TODO exception
	}
        catch(UnsupportedEncodingException e){
            e.printStackTrace();
            return null;
        }
    }
}
